package com.spring.lesson001.demo11;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author vhans
 */
public class LookupMethodTest {
    @Test
    public void serviceByScope() {
        String beanXml = "serviceByScope0111.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println("serviceA:" + context.getBean("serviceA"));
        System.out.println("serviceA:" + context.getBean("serviceA"));
        ServiceB bean = context.getBean(ServiceB.class);
        System.out.println(bean.getServiceA());
        System.out.println(bean.getServiceA());
    }

    @Test
    public void applicationContextAware() {
        String beanXml = "applicationContextAware0111.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        com.spring.lesson001.demo11.applicationcontextaware.ServiceB bean = context.getBean(com.spring.lesson001.demo11.applicationcontextaware.ServiceB.class);
        bean.say();
        bean.say();
    }

    @Test
    public void lookupMethod() {
        String beanXml = "lookup-method0111.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        com.spring.lesson001.demo11.lookupmethod.ServiceB bean = context.getBean(com.spring.lesson001.demo11.lookupmethod.ServiceB.class);
        bean.say();
        bean.say();
    }

    @Test
    public void methodReplacer() {
        String beanXml = "methodReplacer0111.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        com.spring.lesson001.demo11.methodReplacer.ServiceB bean = context.getBean(com.spring.lesson001.demo11.methodReplacer.ServiceB.class);
        bean.say();
        bean.say();
    }
}
